package com.orchard.orchardfarmmanagementsystem.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.orchard.orchardfarmmanagementsystem.entity.Inventory;
import com.orchard.orchardfarmmanagementsystem.entity.Materials;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface InventoryMapper extends BaseMapper<Inventory> {
    @Update("UPDATE inventory SET current_quantity = current_quantity - #{quantity} WHERE material_id = #{materialId} AND current_quantity >= #{quantity}")
    int deductInventory(@Param("materialId") Integer materialId, @Param("quantity") Integer quantity);

    @Update("UPDATE inventory SET current_quantity = current_quantity + #{quantity} WHERE material_id = #{materialId}")
    int returnInventory(@Param("materialId") Integer materialId, @Param("quantity") Integer quantity);
}